package com.example.ch2;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.example.myapplicationtest4.R;
import com.example.util.Mlog;

public class FirstActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.ch2_first_layout);
        Button button = (Button) findViewById(R.id.ch2_test_button);
        button.setOnClickListener(a->{
//            Toast.makeText(this, "点了", Toast.LENGTH_SHORT).show();
//            finish();
//            Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
//            Intent intent = new Intent("com.example.ch2.ACTION_START");
//            intent.addCategory("com.example.ch2.MY_CATEGORY");
//            打开网页
//            Intent intent = new Intent(Intent.ACTION_VIEW);
//            intent.setData(Uri.parse("http://www.baidu.com"));
//            打开拨号
//            Intent intent = new Intent(Intent.ACTION_DIAL);
//            intent.setData(Uri.parse("tel:10086"));
            Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
            intent.putExtra("extra_data","hello SecondActivity");
            startActivityForResult(intent,1);
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        super.onOptionsItemSelected(item);
        int itemId = item.getItemId();
        if (itemId == R.id.add_item) {
            Toast.makeText(this, "You clicked Add", Toast.LENGTH_SHORT).show();
        } else if (itemId == R.id.remove_item) {
            Toast.makeText(this, "You clicked Remove", Toast.LENGTH_SHORT).show();
        }
        return true;
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Mlog.i("in FirstActivity onActivityResult,requestCode:"+requestCode+",resultCode:"+resultCode);
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                String dataReturn = data.getStringExtra("data_return");
                Toast.makeText(this, dataReturn, Toast.LENGTH_SHORT).show();
            }
        }
    }
}